home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-06-03 | 4.5 KB | 174 lines | [TEXT/MPS ] |
- /*************************************************************************************
- *
- * Object Oriented Shell
- *
- * Menus.cp - C Source File
- *
- * Copyright © Apple Computer, Inc. 1988 - 1993
- * All rights reserved.
- *
- * This file contains the code which handles the user selecting a menu item.
- * This code will automatically support the AppleMenuItems as well as call
- * a WindowObj of yours called "AboutObj" -- which is a kind of WindowObj in which
- * it's oversimplified to handle your about box.
- *
- *************************************************************************************/
-
- #include "main.h"
- #include <Traps.h>
- #include "WindowObj.Link"
-
- /**************************************************************************************
-
- AdjustMenus
-
- Enable and disable menus based on the current state. The user can only
- select enabled menu itmes. We set up all the menuitems before calling
- MenuSelect or MenuKey, since these are the only times that menu item can
- be selected. Note that MenuSelect is also the only time the user will see
- menu itmes. This approach to deciding what enable/disable state a menu
- item has has the advantage of concentrating all the decisionmaking in one
- routine, as opposed to being spread throughout the application. Other
- application designs may take a different approach that is just as valid.
-
- ***************************************************************************************/
- void AppAdjustMenus()
- {
- WindowPtr window;
- MenuHandle menu;
-
- window = FrontWindow();
-
- menu = GetMHandle(mFile);
- if( menu)
- {
- if( window != NIL)
- {
- EnableItem(menu, iNew); // Enable the items, one at a time...
- EnableItem(menu, iOpen);
- EnableItem(menu, iClose);
- DisableItem(menu, iSave);
- DisableItem(menu, iSaveAs);
- DisableItem(menu, iRevert);
- DisableItem(menu, iPageSetup);
- DisableItem(menu, iPrint);
- }
- else
- {
- EnableItem(menu, iNew); // Enable the items, one at a time...
- EnableItem(menu, iOpen);
- DisableItem(menu, iClose);
- DisableItem(menu, iSave);
- DisableItem(menu, iSaveAs);
- DisableItem(menu, iRevert);
- DisableItem(menu, iPageSetup);
- DisableItem(menu, iPrint);
- }
-
- EnableItem(menu, iQuit);
- }
-
- menu = GetMHandle( mEdit);
- if( menu)
- {
- if( IsDAWindow(window))
- {
- EnableItem(menu, iUndo);
- EnableItem(menu, iCut);
- EnableItem(menu, iCopy);
- EnableItem(menu, iClear);
- EnableItem(menu, iPaste);
- }
- else
- {
- DisableItem(menu, iUndo);
- DisableItem(menu, iCut);
- DisableItem(menu, iCopy);
- DisableItem(menu, iClear);
- DisableItem(menu, iPaste);
- }
- }
- }
-
- /**************************************************************************************
-
- AppMenu
-
- This is called when an item is chosen from the menu bar (after calling
- MenuSelect or MenuKey). It performs the right operation for each command.
- It is good have both the result of MenuSelect and MenuKey go to one
- routine like this to keep everything organized.
-
- ***************************************************************************************/
- void AppMenu(short menu, short item)
- {
- Str255 daName;
- WINDOWOBJ *a;
-
- switch( menu )
- {
- case mApple:
- switch( item)
- {
- case iAbout:
- (void) Alert(rAboutAlert, NIL);
- default:
- GetItem(GetMHandle(mApple), item, daName);
- (void) OpenDeskAcc(daName);
- break;
- }
- break;
-
- case mFile:
- switch( item)
- {
- case iNew:
- a = new WINDOWOBJ;
- if( a->NewWindowObj() == false)
- delete a;
- break;
- case iClose:
- CloseAnyWindow(FrontWindow());
- break;
- case iQuit:
- gQuit = true; // At first it's true, we're quitting...
- gQuit = CloseAllAppWindows( ) ? false : true;
- // This will tell us if the
- // user selected CANCEL for any window.
- // If the user selected CANCEL, a true
- // will be returned to gQuit; However,
- // gQuit needs to be true only if
- // no windows were CANCELled.
- break;
- }
- break;
-
- case mEdit:
- switch( item)
- {
- /* Call SystemEdit for DA editing & multifinder */
- /* since we personally don't do any editing */
- case iUndo:
- case iCut:
- case iCopy:
- case iPaste:
- case iClear:
- (void) SystemEdit(item-1);
- break;
- }
- break;
- case 132:
- a = new WINDOWOBJ;
- if( a)
- {
- MenuHandle gPicturesMenu = GetMHandle( 132);
-
- GetItem( gPicturesMenu, item, a->pictureName);
- if( a->NewWindowObj() == false)
- delete a;
- }
- break;
- }
- HiliteMenu(0);
- }
-